define(['angular'], function(angular) {
    angular.module('common_dir', [])
    .value('THROTTLE_MILLISECONDS', null)
    // 请求数据等待层
    .directive('loadingDir', ['$timeout', '$interval', 'header', function($timeout, $interval, header) {
        return {
            restrict: 'AE',
            scope: {
                isShow: '@isShow' // 是否显示loading层标志位
            },
            templateUrl: '../template/loading.html',
            link: function(scope, element, attrs) {
                scope.showLoadingLayer = true; // 默认隐藏loading层
                scope.loadMsg = "加载中......";
             // 倒计时60秒，60秒无响应，回首页
            var startLimiter = function () {
                var time = 20;
                return $interval(function() {
                	if(time == 2){
                		scope.loadMsg = "加载超时,请重试";
                	}
                    if (!time--) {
                    	scope.showLoadingLayer = true;
                    }
                }, 1000);
            };
                var ltId; // 倒计时id
                scope.$watch('isShow', function() {
                    if (scope.isShow === 'true') {
                    	scope.loadMsg = "加载中......";
                    	ltId = startLimiter();
                        scope.showLoadingLayer = false;
                    } else if (scope.isShow === 'false') {
                        $interval.cancel(ltId);
                        scope.showLoadingLayer = true;
                    }
                });
             }
        };
    }])
    //显示导航条loading
    .directive('loadingNav', ['$timeout', '$interval', 'header', function($timeout, $interval, header) {
        return {
            restrict: 'AE',
            scope: {
                isShow: '@isShow' // 是否显示loading层标志位
            },
            templateUrl: '../template/loadingNav.html',
            link: function(scope, element, attrs) {
                scope.showLoadingNav = true; // 默认隐藏loading层
                scope.loadMsg = "加载中......";
             // 倒计时60秒，60秒无响应，回首页
            var startLimiter = function () {
                var time = 20;
                return $interval(function() {
                	if(time == 2){
                		scope.loadMsg = "加载超时,请重试";
                	}
                    if (!time--) {
                    	scope.showLoadingNav = true;
                    }
                }, 1000);
            };
                var ltId; // 倒计时id
                scope.$watch('isShow', function() {
                    if (scope.isShow === 'true') {
                    	scope.loadMsg = "加载中......";
                    	ltId = startLimiter();
                        scope.showLoadingNav = false;
                    } else if (scope.isShow === 'false') {
                        $interval.cancel(ltId);
                        scope.showLoadingNav = true;
                    }
                });
             }
        };
    }])
    // 半透明背景loading
    .directive('loadingTpr', ['$timeout', '$interval', 'header', function($timeout, $interval, header) {
        return {
            restrict: 'AE',
            scope: {
                isShow: '@isShow' // 是否显示loading层标志位
            },
            templateUrl: '../template/loadingTpr.html',
            link: function(scope, element, attrs) {
                scope.showLoadingTpr = true; // 默认隐藏loading层
                scope.loadMsg = "加载中......";
             // 倒计时60秒，60秒无响应，回首页
            var startLimiter = function () {
                var time = 20;
                return $interval(function() {
                	if(time == 2){
                		scope.loadMsg = "加载超时,请重试";
                	}
                    if (!time--) {
                    	scope.showLoadingTpr = true;
                    }
                }, 1000);
            };
                var ltId; // 倒计时id
                scope.$watch('isShow', function() {
                    if (scope.isShow === 'true') {
                    	scope.loadMsg = "加载中......";
                    	ltId = startLimiter();
                        scope.showLoadingTpr = false;
                    } else if (scope.isShow === 'false') {
                        $interval.cancel(ltId);
                        scope.showLoadingTpr = true;
                    }
                });
             }
        };
    }])
    // 页面顶部导航条
	.directive('navDir', ['header', '$location', '$rootScope', '$interval', '$timeout','$location', function(header, $location, $rootScope, $interval, $timeout,$location) {
        return {
            restrict: 'AE',
            scope: {
				leftBtFn: '&leftBtFn', // 返回键处理方法
				rightBtFn: '&rightBtFn', // 右侧按钮处理方法
				isFlag: '@flag',		//顶部显示'1'：显示案源库、2：
				isShow: '@isShow'		//控制萤火虫顶部是否显示
            },
            templateUrl: header.templateUrl,
            link: function(scope, element, attrs) {
            	//监听顶部显示
            	scope.isshow_flex = false;
            	scope.$watch('isShow', function() {
                    if (scope.isShow === 'true') {
                    	scope.isshow_flex = true;
                    }else if (scope.isShow === 'false') {
                    	scope.isshow_flex = false;
                    }
                });
            	
            	//监听顶部'1'：案源库、'2':案件概况、'3'：赢火虫免息贷、'4':我的、'5': 注册、'6':设置密码、'7':完善资料（普通）、'8':完善资料（律师）、
            	//'9':注册成功、 '10': 登录、"11": 找回密码 、"12":"我的收藏"、"13":律师个人信息、"14":普通个人信息,"15"："找回密码(重设)"、"16": "找回密码成功"、
            	//"17": "重置密码"、"18":"重置密码成功"、"19": "我的贷款"、"20": "我的发布"、"21":"发布成功"、"22":案源申请已提交、"23":"我的案件列表"、"24":"我的推荐"
            	//"25": "贷款申请失败"、"26": "发布未通过审核列表"、"27": "还款中明细"、"28":"我的推荐-已逾期"、"29":"我的贷款-还款中"、"30":贷款申请提交成功、"31":还款提交成功受理
            	//"32":"审核贷款"、"33":同意此项贷款、"34":决绝此项贷款、"35":"我的推荐-还款中"、"36":"我的还款-待审核"、"37"："我的发布-待审核"、"38"："发布失败详情"
            	//"39":"我的案件申请中"、"40":"查看我的案件"、"41": "我的案件未通过审核"、'42':"信息"、"43":"信息详情"、"44":"发布成功详情"、"45":"发布成功未修改过"、'46':"我的贷款概要"
            	//'47': "还款明细" 、'48': "关于我们" 、'49':"帮助"、'50':"协议"、'51'："修改账号"、"52"："亮度表"、65：账户信息、66：更改用户名
            	scope.$watch('isFlag', function() {
        			if(scope.isFlag === '1'){
        				setngIfFalse();
        				scope.caseSrcLib = true;
//        				scope.backIcon = false;
        			}else if(scope.isFlag === '2'){
        				setngIfFalse();
        				scope.caseProfile = true;
        				scope.shareAndCollect = true;
                        scope.isCollectLight = false;
        				/*$timeout(function(){
        					judgeCollect();
        				},0);*/
        			}else if(scope.isFlag === '2-1'){
        				setngIfFalse();
        				scope.caseProfile = true;
        				scope.shareAndCollect = true;
        				scope.isCollectLight = true;
        			}else if(scope.isFlag === '3'){
        				setngIfFalse();
        				scope.loan = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '3-1' || scope.isFlag === '3-2' || scope.isFlag === '3-4'){
        				setngIfFalse();
        				scope.loan = true;
        			}else if(scope.isFlag === '3-3'){
        				setngIfFalse();
        				scope.searchLs = true;
        			}else if(scope.isFlag === '4'){
        				setngIfFalse();
        				scope.mine = true;
        				//scope.register = true;
        				scope.isGreen_bg = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '4-1' || scope.isFlag === '4-2'){
        				setngIfFalse();
        				scope.mine = true;
        				scope.isGreen_bg = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '5'){
        				setngIfFalse();
        				scope.registerMid = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '6'){
        				setngIfFalse();
        				scope.setPwd = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '7'){
        				setngIfFalse();
        				scope.completePt = true;
        				scope.skip = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '8'){
        				setngIfFalse();
        				scope.completeLs = true;
        				scope.skip = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '8-1'){
        				setngIfFalse();
        				scope.completeData = true;
        				scope.skip = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '9'){
        				setngIfFalse();
        				scope.regSuccess = true;
        				scope.isGreen_bg = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '10'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.login = true;
        			}else if(scope.isFlag === '10-1'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.authCodeLogin = true;
        			}else if(scope.isFlag === '11' || scope.isFlag === '11-1'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.findPwd = true;
        			}else if(scope.isFlag === '12'){
        				setngIfFalse();
        				scope.myCollection = true;
        				scope.delCollect = true;
        			}else if(scope.isFlag === '12-1'){
        				setngIfFalse();
        				scope.myCollection = true;
        			}else if(scope.isFlag === '12-2'){
        				setngIfFalse();
        				scope.myCollection = true;
        				scope.delCollect = true;
                		scope.comCollect = false;
        			}else if(scope.isFlag === '13'){
        				setngIfFalse();
        				scope.personalInfo = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '13-1'){
        				setngIfFalse();
        				scope.personalInfo = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '14'){
        				setngIfFalse();
        				scope.personalInfo = true;
        				scope.isGreen_bg = true;
        			}else if(scope.isFlag === '15'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.findPwd = true;
        			}else if(scope.isFlag === '16'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.findPwd = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '17' || scope.isFlag === '17-1' || scope.isFlag === '17-2'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.modifyPwd = true;
        			}else if(scope.isFlag === '18'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.modifyPwd = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '19'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myLoan = true;
        			}else if(scope.isFlag === '20'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myIssue = true;
        			}else if(scope.isFlag === '21'){
        				setngIfFalse();
        			}else if(scope.isFlag === '22'){
        				setngIfFalse();
        			}else if(scope.isFlag === '23'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myCaseList = true;
        			}else if(scope.isFlag === '24'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myRecommend = true;
        			}else if(scope.isFlag === '25'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.loanFail = true;
        			}else if(scope.isFlag === '26'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.issueFail = true;
        				scope.delIssue = true;
        			}else if(scope.isFlag === '26-1'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.issueFail = true;
        			}else if(scope.isFlag === '27'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.repayDetail = true;
        			}else if(scope.isFlag === '28'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myRecOverdue = true;
        			}else if(scope.isFlag === '29'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myRepaying = true;
        			}else if(scope.isFlag === '30'){
        				setngIfFalse();
        			}else if(scope.isFlag === '31'){
        				setngIfFalse();
        				scope.backIcon = false;
        			}else if(scope.isFlag === '32'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.checkLoan = true;
        			}else if(scope.isFlag === '33'){
        				setngIfFalse();
        				scope.backIcon = false;
        			}else if(scope.isFlag === '34'){
        				setngIfFalse();
        				scope.backIcon = false;
        			}else if(scope.isFlag === '35'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myRecRepay = true;
        			}else if(scope.isFlag === '36'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.loanWaitCheck = true;
        			}else if(scope.isFlag === '37'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.issueCheck = true;
        			}else if(scope.isFlag === '38'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.issueFail = true;
        			}else if(scope.isFlag === '39'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.caseApplying = true;
        			}else if(scope.isFlag === '40'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.caseProfile = true;
        			}else if(scope.isFlag === '41'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.caseNoApply = true;
        			}else if(scope.isFlag === '42'){
	    				setngIfFalse();
	    				scope.isGreen_bg = true;
	    				scope.msgCenter = true;
        			}else if(scope.isFlag === '43'){
	    				setngIfFalse();
	    				scope.isGreen_bg = true;
	    				scope.msgCenter = true;
        			}else if(scope.isFlag === '44'){
        				setngIfFalse();
        				scope.caseProfile = true;
        			}else if(scope.isFlag === '45'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.issueSuccess = true;
        			}else if(scope.isFlag === '46'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.loanOutline = true;
        			}else if(scope.isFlag === '47'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.loanRepayDet = true;
        			}else if(scope.isFlag === '48'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.aboutUs = true;
        			}else if(scope.isFlag === '49'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.helpUs = true;
        			}else if(scope.isFlag === '50'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.protocol = true;
        			}else if(scope.isFlag === '51'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changeMobile = true;
        			}else if(scope.isFlag === '51-1'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changeMobile = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '52'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.brightness = true;
        			}else if(scope.isFlag === '53'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.myQrcodeName = true;
        			}else if(scope.isFlag === '54'){
        				setngIfFalse();
//        				scope.isGreen_bg = true;
        				scope.myIncome = true;
        			}else if(scope.isFlag === '55'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.applyAgentName = true;
        			}else if(scope.isFlag === '56'){
        				setngIfFalse();
        				scope.invest = true;
        			}else if(scope.isFlag === '57'){
        				setngIfFalse();
        				scope.applyInvest = true;
        			}else if(scope.isFlag === '58'){
        				setngIfFalse();
        				scope.applySurvey = true;
        			}else if(scope.isFlag === '59'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.queryInvestList = true;
        			}else if(scope.isFlag === '60'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.titleNameVariable = true;
        			}else if(scope.isFlag === '60-0'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.titleNameVariable = true;
                        scope.editText='修改';
        			}else if(scope.isFlag === '60-1'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.titleNameVariable = true;
        				scope.editText='完成';
        			}else if(scope.isFlag === '61'){
        				setngIfFalse();
        				scope.knowAssets = true;
        			}else if(scope.isFlag === '62'){
        				setngIfFalse();
        				scope.applyNpl = true;
                        scope.isGreen_bg = true;
        			}else if(scope.isFlag === '63'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.queryNpl = true;
        			}else if(scope.isFlag === '64'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.nplDetail = true;
        			}else if(scope.isFlag === '65'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.accountInfo = true;
        			}else if(scope.isFlag === '66'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changeName = true;
        			}else if(scope.isFlag === '67'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.setLoginPwd = true;
        			}else if(scope.isFlag === '68'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changePwdByOldPwd = true;
        			}else if(scope.isFlag === '69'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changePwdByMobile = true;
        			}else if(scope.isFlag === '70'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.changeNo = true;
        			}else if(scope.isFlag === '71'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.messageIndex = true;
        			}else if(scope.isFlag === '72'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.titleNameVariable = true;
        			}else if(scope.isFlag === '73'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.applyRisk = true;
        			}else if(scope.isFlag === '73-0'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.applyRisk = true;
        				scope.editText = '修改';
        			}else if(scope.isFlag === '74'){
        				setngIfFalse();
        				scope.isGreen_bg = true;
        				scope.applyCaseDetail= true;
        			}else if(scope.isFlag === '75'){
        				setngIfFalse();
        				scope.caseProfile = true;
                        scope.isCollectLight = false;
                        scope.collect = true;
        			}else if(scope.isFlag === '75-1'){
        				setngIfFalse();
        				scope.caseProfile = true;
                        scope.isCollectLight = true;
                        scope.collect = true;
        			}else if(scope.isFlag === '76'){
        				setngIfFalse();
        				scope.caseProfile = true;
        				scope.backIcon = false;
        			}else if(scope.isFlag === '77'){
                        setngIfFalse();
                        scope.isGreen_bg = true;
                        scope.diagRealize = true;
                    }else if(scope.isFlag === '78'){
                        setngIfFalse();
                        scope.isGreen_bg = true;
                        scope.lawsuitRealize = true;
                    }else if(scope.isFlag === '79'){
                        setngIfFalse();
                        scope.isGreen_bg = true;
                        scope.caseRealize = true;
                    }else if(scope.isFlag === '80'){
                        setngIfFalse();
                        scope.isGreen_bg = true;
                        scope.creditorRealize = true;
                    }
                });
                //监听标题栏
                scope.$on('changeNavTitleFromBody',function(e,d){
                    $timeout(function(){
                        scope.titleName=d;
                    },0)
                });
            	//将所有ng-if置空
            	function setngIfFalse(){
            		//中间
            		scope.caseSrcLib = false;
            		scope.caseProfile = false;
            		scope.loan = false;
            		scope.mine = false;
            		scope.registerMid = false;
            		scope.setPwd = false;
            		scope.completePt = false;
            		scope.completeLs = false;
            		scope.regSuccess = false;
            		scope.login = false;
            		scope.authCodeLogin = false;
            		scope.findPwd = false;
            		scope.myCollection = false;
            		scope.personalInfo = false;
            		scope.modifyPwd = false;
            		scope.myLoan = false;
            		scope.myIssue = false;
            		scope.myCaseList = false;
            		scope.myRecommend = false;
            		scope.loanFail = false;
            		scope.issueFail = false;
            		scope.repayDetail = false;
            		scope.myRecOverdue = false;
            		scope.myRepaying = false;
            		scope.checkLoan = false;
            		scope.myRecRepay = false;
            		scope.loanWaitCheck = false;
            		scope.issueCheck = false;
            		scope.caseApplying = false;
            		scope.caseNoApply = false;
            		scope.msgCenter = false;
            		scope.issueSuccess = false;
            		scope.loanOutline = false;
            		scope.loanRepayDet = false;
            		scope.aboutUs = false;
            		scope.helpUs = false;
            		scope.protocol = false;
            		scope.completeData = false;
            		scope.changeMobile = false;
            		scope.searchLs = false;
            		scope.brightness = false;
            		scope.myQrcodeName = false;
            		scope.myIncome = false;
            		scope.applyAgentName = false;
            		scope.invest = false;
            		scope.applyInvest = false;
            		scope.applySurvey = false;
            		scope.queryInvestList = false;
            		scope.investDetail = false;
            		scope.knowAssets = false;
            		scope.applyNpl = false;
            		scope.queryNpl = false;
            		scope.nplDetail = false;
                    scope.accountInfo = false;
                    scope.changeName = false;
                    scope.setLoginPwd = false;
                    scope.changePwdByOldPwd = false;
                    scope.changePwdByMobile = false;
                    scope.changeNo = false;
                    scope.messageIndex = false;
                    scope.applyRisk = false;
                    scope.titleNameVariable = false;
                    scope.applyCaseDetail = false;
					scope.collect = false;
                    scope.diagRealize = false;
                    scope.lawsuitRealize = false;
                    scope.caseRealize = false;
                    scope.creditorRealize = false;
            		//右边
            		//scope.register = false;
            		scope.skip = false;
            		scope.delIssue = false;
            		scope.delCollect = false;
            		scope.complete = false;
            		scope.comCollect = false;
            		scope.shareAndCollect = false;
            		scope.editText = false;

            		
            		//左边
            		scope.backIcon = true;
            		
            		//导航样式
            		scope.isGreen_bg = false;
            	}
            	
            	//调用接口判断是否收藏过
            	function judgeCollect(){
            		var headerInfo = {},bizInfo = {};
                	headerInfo.pageNum = '';
                	headerInfo.pageSize = '';
                	headerInfo.sessionId = transData.sessionId;
                	
                	bizInfo.type = "0";
                	bizInfo.id = resultData.caseDetailData.caseId;
                	yhc.biz("queryFavorite",headerInfo,bizInfo,
                			function(ret){
                				if(ret != "" && ret != null && ret != '[]'){
                					$timeout(function(){
                						var tempData = JSON.parse(ret);
                        				if(tempData.isSuccess == 'T'){
                        					if(tempData.body == '1'){//已存在
                        						scope.isCollectLight = true;
                        					}else if(tempData.body == '0'){
                        						scope.isCollectLight = false;
                        					}
                        				}
                					},0);
                				}
                	}, 
            		 	function(){});
            	}
            	
            	//点击删除收藏夹列表
            	function delCollectList(){
            		var headerInfo = {},bizInfo = {};
                	headerInfo.pageNum = '';
                	headerInfo.pageSize = '';
                	headerInfo.sessionId = transData.sessionId;
                	
                	bizInfo.idList = [resultData.caseDetailData.caseId];
                	
                	yhc.biz("delFavorite",headerInfo,bizInfo,
                			function(ret){
        						if(ret != "" && ret != null && ret != '{}' && ret != 'null'){
        							var tempData = JSON.parse(ret);
        							if(tempData.isSuccess == "T"){
        								$timeout(function(){
        									scope.isCollectLight = false;
        								},0);
        							}
        						}
        				 	}, 
            		 	function(){});
            	}
            	
            	//点击收藏
            	scope.collectInfo = function(){
            		if(transData.mobileNo != "" && transData.sessionId != ""){
            			/*if(scope.isCollectLight){
            				delCollectList();
            			}else{
            				scope.isCollectLight = true;
            				scope.rightBtFn({"rightManage":{'name':"collectionEvent",'val':""}});
            			}*/
                        scope.rightBtFn({"rightManage":{'name':"collectionEvent",'val':""}});
            		}else{
            			transData.gotoUrl = "/caseProfile";
            			scope.$emit("goNext","/login");
            		}
            		
            	}
            	
            	//点击分享
            	scope.shareInfo = function(){
            		scope.rightBtFn({"rightManage":{'name':"shareEvent",'val':""}});
            	}
            	
            	//点击注册事件
            	scope.registerFn = function(){
            		scope.rightBtFn({"rightManage":{'name':"registerEvent",'val':""}});
            	}
            	//点击跳过
            	scope.skipFn = function(){
            		scope.rightBtFn({"rightManage":{'name':"skipEvent",'val':""}});
            	}
            	
            	//点击删除未通过发布
            	scope.deleteIssu = function(){
            		scope.delIssue = false;
            		scope.complete = true;
            		scope.rightBtFn({"rightManage":{'name':"deleteEvent",'val':""}});
            	}
            	
            	//点击完成删除
            	scope.completeIssu = function(){
            		scope.delIssue = true;
            		scope.complete = false;
            		scope.rightBtFn({"rightManage":{'name':"deleteComEvent",'val':""}});
            	}
            	
            	//点击删除收藏案件
            	scope.deleteCollect = function(){
            		scope.delCollect = false;
            		scope.comCollect = true;
            		scope.rightBtFn({"rightManage":{'name':"deleteCollectEvent",'val':""}});
            	}
            	
            	//点击完成删除收藏案件
            	scope.comCollectFn = function(){
            		scope.delCollect = true;
            		scope.comCollect = false;
            		scope.rightBtFn({"rightManage":{'name':"deleteCollectComEvent",'val':""}});
            	}
            	//点击编辑
            	scope.editTextFn = function(){
            		scope.rightBtFn({"rightManage":{'name':"editTextEvent",'val':""}});
            	}
            	
            	
				var newValue = '/';
				// 调用 bodyCtrl 返回按钮事件
				function backEventFn() {
					$timeout(function(){scope.leftBtFn({"routeUrl":newValue});},0)
				};
				// 返回按钮事件
				scope.backEvent = backEventFn;
//				 安卓实体返回按钮
				document.addEventListener('backbutton', backEventFn, false);
				// 监听传到该指令的标志位，改变导航条状态
				$rootScope.$on('$locationChangeStart', function() {
					newValue = $location.path();
				});
            }
        };
    }])
    //下拉刷新
    .directive('refreshDir', ['header', '$location', '$rootScope', '$interval', '$timeout','$location', function(header, $location, $rootScope, $interval, $timeout,$location) {
        return {
            restrict: 'AE',
            scope: {
        		htmlStru: '@html'		//顶部显示'1'：显示案源库、2：
            },
            templateUrl: header.refreshUrl,
            link: function(scope, element, attrs) {
                // 此节点是controller传入到指令里面的节点
            	var htmlStru = "";
            	scope.$watch('htmlStru', function() {
            		htmlStru = scope.htmlStru;
            		if(htmlStru){
            			var scrollNode = document.querySelector(htmlStru);

            			var refreshFireflyNode = document.querySelector("#refresh_firefly");
                        var refreshTextNode = document.querySelector("#refresh");
                        var originY, currentY, dragDistance, scrollTopPos;
                        var startString = 'translate3d(0,',
            				endString = 'px, 0)';
                        scrollNode.addEventListener("touchstart", function(e) {
                            scrollTopPos = this.scrollTop;
                            originY = e.targetTouches[0].pageY;
                            scrollNode.style['-webkit-transition-duration'] = '0s';
                            refreshFireflyNode.style['-webkit-transition-duration'] = '0s';
                            refreshTextNode.style['-webkit-transition-duration'] = '0s';
                        }, false);
                        scrollNode.addEventListener("touchmove", function(e) {
                            currentY = e.targetTouches[0].pageY;
                            dragDistance = currentY - originY;
                            if (scrollTopPos == 0) {
                                if (dragDistance > 0 && dragDistance <= 200) {
                                    e.preventDefault();
                                    this.style['-webkit-transform'] = refreshFireflyNode.style['-webkit-transform'] = refreshTextNode.style['-webkit-transform'] = startString + dragDistance/2 + endString;
                                    if (dragDistance > 100) {
                                        refreshTextNode.innerText = "松开看看";
                                        refreshFireflyNode.src = "img/refresh_firefly_eye.png";
                                    } else {
                                        refreshTextNode.innerText = "下拉刷新";
                                    }
                                }
                            }
                        }, false);
                        
                        scrollNode.addEventListener('touchend', function(e) {
                            this.style['-webkit-transition-duration'] = refreshFireflyNode.style['-webkit-transition-duration'] = refreshTextNode.style['-webkit-transition-duration'] = '0.4s';
                            if (dragDistance > 100) {
                                this.style['-webkit-transform'] = refreshFireflyNode.style['-webkit-transform'] = refreshTextNode.style['-webkit-transform'] = startString + 60 + endString;
                                refreshTextNode.innerText = "正在刷新...";
                                setTimeout(function() {
                                    restore();
                                }, 1700);
                            } else {
                                this.style['-webkit-transform'] = refreshFireflyNode.style['-webkit-transform'] = refreshTextNode.style['-webkit-transform'] = startString + 0 + endString;
                            }
                            dragDistance = 0;
                        }, false);
                        
                        if(htmlStru == "#case_src_lib .wrap_box"){
                        	//refreshDefault();
                        }
            		}
            		
            		function restore() {
            			refreshFireflyNode.src = "img/refresh_firefly.png";
                        refreshFireflyNode.style['-webkit-transition-duration'] = '0.4s';
                        refreshFireflyNode.style['-webkit-transform'] = startString + "80" + endString;
                        setTimeout(function() {
                            refreshFireflyNode.style['-webkit-transition-duration'] = '0.8s';
                            refreshFireflyNode.style['-webkit-transform'] = startString + "-16" + endString;
                        }, 400);
                        setTimeout(function() {
                            scrollNode.style['-webkit-transform'] =  refreshTextNode.style['-webkit-transform'] = startString + 0 + endString;
                        }, 1200);
                        
                        setTimeout(function() {
                            refreshTextNode.innerText = "下拉刷新";
                        }, 1700);
                        
                        if(htmlStru == "#case_src_lib .wrap_box"){
                        	scope.$emit("caselibRefresh",true);
                        }else if(htmlStru == "#home_page .scrollTempCase"){
                        	scope.$emit("caselibRefreshStep1",true);
                        }
                    }
            		
            		function refreshDefault() {
                        refreshFireflyNode.src = "img/refresh_firefly_eye.png";
                        scrollNode.style['-webkit-transition-duration'] = refreshFireflyNode.style['-webkit-transition-duration'] = refreshTextNode.style['-webkit-transition-duration'] = '0.4s';
                        scrollNode.style['-webkit-transform'] = refreshFireflyNode.style['-webkit-transform'] = refreshTextNode.style['-webkit-transform'] = startString + 60 + endString;
                        refreshTextNode.innerText = "正在刷新...";
                        setTimeout(function() {
                        	 restore();
                        }, 1700);
                    }
                });
            }
        };
    }])
    //密码软键盘
    .directive('keyPad', ['keypad', '$timeout','header', function(keypad, $timeout,header) {
    	 return {
             restrict: 'AE',
             scope: {
                 inputVal: '=iVal', // 输入框值
                 assignPwd: '@assignPwd',   //赋给密码值
                 pwdShow: '@pwdShow'		//控制密码键盘是否显示
             },
             templateUrl: header.pwdkeyboardUrl,
             link: function(scope, element, attrs) {
            	 scope.inputVal = "";
            	 scope.pwdSlidUp = true;
            	 scope.$watch('pwdShow', function(newValue, oldValue) {
            		 if(newValue *1 > 1){
            			 scope.pwdSlidUp = true;
            		 }else{
            			 if(newValue != '0' &&  newValue != '1'){
            				 scope.inputVal = "";
            			 }
            			 scope.pwdSlidUp = false;
            		 }
                 });
            	 
            	 scope.$watch('assignPwd', function(newValue, oldValue) {
            		 var tempData = scope.assignPwd;
            		 scope.inputVal = tempData.substring(2);
                 });
     
                 // 键盘所需数据
                 scope.keypadData = [
                     {no: '1'},
                     {no: '2'},
                     {no: '3'},
                     {no: '4'},
                     {no: '5'},
                     {no: '6'},
                     {no: '7'},
                     {no: '8'},
                     {no: '9'}
                 ];

                 // 删除按钮功能
                 scope.del = function() {
                     scope.inputVal = scope.inputVal.slice(0, -1);
                 };
                 
                 // 点击键盘，验证、传值和触发效果
                 scope.getValue = function(val) {
                     scope.inputVal = keypad['pwd'].getValue(scope.inputVal, val);
                 };
                 
                 //点击下滑密码键盘
                 scope.slideDownFn = function(){
                	 scope.pwdSlidUp = false;
                 }
             }
         };
    }])
	// touchstart
	.directive('ngTouchstart', ['$timeout', function($timeout) {	
		return {
            restrict: 'A',
			scope: {
				triggerEvent: '&ngTouchstart'
			},
            link: function(scope, element, attrs) {
				element.on('touchstart', function(event) {
//					element.addClass('ng-click-active');
					scope.triggerEvent();
				});
            }
        };
	}])
	.directive('onFinishRenderFilters', ['$timeout', function ($timeout) {
		return {
			restrict: 'A',
			link: function(scope,element,attr) {
				if (scope.$last === true) {
					var finishFunc=scope.$parent[attr.onFinishRenderFilters];
					if(finishFunc)
					{
						finishFunc();
					}
				}
			}
		};
		}])
	.directive('ngCacheImgSrc', ['$timeout', function ($timeout) {
	return {
		restrict: 'A',
		link: function(scope,element,attrs) {
			if(imgMap[attrs.ngCacheImgSrc] == null){
				var img = new Image();
				imgMap[attrs.ngCacheImgSrc] = img;
				img.src = attrs.ngCacheImgSrc;
				attrs.src = img.src;
				 attrs.$set('src', img.src);
			}else{
				 attrs.$set('src', imgMap[attrs.ngCacheImgSrc].src);
			}
		}
	};
	}]);
	});